<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="plugin/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" href="plugin/header/header.css">
	<link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="plugin/captionHover/captionHover.css">
	<link rel="stylesheet" href="plugin/layui/css/layui.css">
	<link rel="stylesheet" href="plugin/menu/bootsnav.css">
</head>
<style>
.content{
    padding:100px 500px 0px 500px;
    height:970px;
}

.content-inner-info{
	background-color:#fff;
	padding:20px 20px 10px 20px;
	border-radius:15px;
}

.layui-btn-group.demoTable{
	float:right;
}

body{
  height:960px;
}
</style>
<body>
<header class="header-navigation" id="header">
  <#include "menu.ftl">
</header>
<div class="content">
<div class="content-inner">
<div class="content-inner-info">
  <div class="layui-btn-group demoTable">
    <button class="layui-btn" data-type="notice" style="width:200px;"><@spring.message "IdentityConfig.addButton" /></button>
  </div>
  <table class="layui-table" lay-data="{width: 880, height:800, url:'/identityConfig/queryResult', page:true, id:'idTest',limit:20}" lay-filter="demo">
    <thead>
    <tr>
        <!--<th lay-data="{type:'checkbox', fixed: 'left'}"></th>-->
        <th lay-data="{field:'id', width:250, sort: true, fixed: true}"><@spring.message "IdentityConfig.table.id" /></th>
        <th lay-data="{field:'virtual_Name', width:250,sort: true}"><@spring.message "IdentityConfig.table.name" /></th>
        <th lay-data="{field:'identityConfig', width:250,templet:function(obj){return getImg(obj);}}"><@spring.message "IdentityConfig.table.img" /></th>
        <th lay-data="{fixed: 'right', width:125, align:'center', toolbar: '#barDemo'}"></th>
    </tr>
    </thead>
  </table>
  <div style="display:none;">
  <div style="margin-bottom: 5px;" >
    <ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>
  </div>
  </div>
</div>
</div>
</div>
<#include "includeftl/layui.ftl">
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><@spring.message "IdentityConfig.table.del" /></a>
</script>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script src="plugin/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="plugin/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="plugin/header/header.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="plugin/captionHover/captionHover.js"></script>
<script type="text/javascript" src="plugin/layui/layui.js"></script>
<script type="text/javascript" src="plugin/menu/bootsnav.js"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            console.log(data);
            if(obj.event === 'del'){
                layer.confirm('<@spring.message "IdentityConfig.sure.del" />?', function(index){
                    $.post("/identityConfig/delete/"+data.id,function (data) {
                        if (data ==1){
                            alert("<@spring.message 'common.delete.success' />");
                        }else if (data ==0){
                            alert("<@spring.message 'common.delete.error' />");
                        }
                    })
                    obj.del();
                    layer.close(index);
                });
            }
        });

        var $ = layui.$, active = {
             notice: function(othis){

            layer.open({
                title:"<@spring.message 'IdentityConfig.addButton' />",
                type: 1,
                area: ['500px', '200px'],
                content: 
                '<form id="testform" class="layui-form" action="">' +
                '  <div class="layui-form-item">' +
                '    <div style="width:500;height:40px;">'+
                '    <label class="layui-form-label" style="width:200px;float:left;margin-bottom:0;"><@spring.message "IdentityConfig.table.name" />：</label>' +
                '    <input type="text" name="name" style="width:220px;float:left" lay-verify="title" autocomplete="off" placeholder="<@spring.message "IdentityConfig.replace.name" />" class="layui-input" id="virtual_Name">' +
                '    </div><br>'+
                '    <div style="width:500;height:40px;">'+
                '    <label class="layui-form-label" style="width:200px;float:left;margin-bottom:0;"><@spring.message "IdentityConfig.table.img" />：</label>' +
                '    <input type="file" name="filename" id="filename" style="float:left;width:220px">' +
                '    </div>'+
                '  </div>' +
                '</form>' +
                '<button type="button" class="layui-btn" style="margin-left:220px;" onclick="test()"> <@spring.message "IdentityConfig.model.add" /></button>'
                ,end: function () {
                    location.reload();
                }
            });
        }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });


    function test() {
        if($("#virtual_Name").val() =="" || $("#virtual_Name").val() == null){
            alert("<@spring.message 'IdentityConfig.replace.name' />");
            return;
        }

        if ($("#filename").val() == null || $("#filename").val() == "") {
            alert("<@spring.message 'IdentityConfig.replace.img' />");
            return ;
        }

        var fd = new FormData($("#testform")[0]);
        $.ajax({
            url: "/identityConfig/addVirtualtype",
            type: "POST",
            data: fd,
            processData: false,
            contentType: false,
            async:false,
            success : function(data) {
                switch (data){
                    case -2:
                        alert("<@spring.message 'IdentityConfig.error_2' />")
                        break;
                    case -1:
                        alert("<@spring.message 'IdentityConfig.error_1' />")
                        break;
                    case 0:
                        alert("<@spring.message 'IdentityConfig.error_0' />")
                        break;
                    default:
                        layer.closeAll();
                        alert("<@spring.message 'IdentityConfig.success' />")
                }
            },
            error : function(data) {
                alert(("<@spring.message 'IdentityConfig.net.error' />"))
            }
        });
    }
    function getImg(obj){
        console.log(obj);
        return  "<img src='/picture/"+obj.identityConfig+"' style='width: 20px;height: 20px;'></img>"
    }
</script>
</body>
</html>